package Ptolemaiosz;

import java.text.NumberFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PhysicalEntity {

	protected Vector velocity = new Vector();
	protected Vector position = null;
	protected CustomPolygon polygon;
	protected LevelPartManager levelPartManager;
        protected Element element;
                
    public PhysicalEntity() {
        
		SkeletonLogger.logCall();
		
		SkeletonLogger.logReturn();
    }
        
        public void setJumping(boolean b)
            {
                SkeletonLogger.logCall();

                SkeletonLogger.logReturn();

            }
    
        public void setElement(Element e)
            {
                SkeletonLogger.logCall();
		
		SkeletonLogger.logReturn();
		
		this.element = e;            
            }
        
                
        
        public Element getElement()
            {
                SkeletonLogger.logCall();
		
		SkeletonLogger.logReturn();
		
		return element;            
            }

	public Vector getPosition() {
		
		
		SkeletonLogger.logCall();
		
		SkeletonLogger.logReturn();
		
		return this.position;
	}

	/**
	 * 
	 * @param c
	 */
	public void collision(PhysicalEntity c) {
		SkeletonLogger.logCall();
		element.interaction(c.getElement());
		SkeletonLogger.logReturn();
                
               
               if(c.getClass().getName() == "Ptolemaiosz.AvatarPhysicalEntity" && this.getClass().getName() == "Ptolemaiosz.AvatarPhysicalEntity")
                   Controller.println("ESEMENY: utkozes avatarral");
                   
	}

	/**
	 * 
	 * @param deltaTime
	 */
	public void update(long deltaTime) {
		SkeletonLogger.logCall();
		SkeletonLogger.logReturn();
	}

	public CustomPolygon getPolygon() {
		
		
		SkeletonLogger.logCall();
		
		SkeletonLogger.logReturn();
		
		return this.polygon;
	}

	/**
	 * 
	 * @param velocity
	 */
	public void addVelocity(Vector velocity) {
		
                //Kimenet
                //Float formazo inicializalasa
                    NumberFormat  float2tizedes = NumberFormat.getInstance();
                    float2tizedes.setMinimumFractionDigits(2);
                    float2tizedes.setMaximumFractionDigits(2);

                    String kimenet = "";
                    String className = this.getClass().getName();

                    Pattern classNamePattern = Pattern.compile("[^.]+.([^.]+)");

                    Matcher m = classNamePattern.matcher(className);
                        m.find();



                    kimenet = kimenet.concat(m.group(1) + " RegiSebbessegvektora: (" + float2tizedes.format(this.velocity.getX()).replace(',','.') + ", " + float2tizedes.format(this.velocity.getY()).replace(',','.') + ");");
                //Kimenet vege     
            
                SkeletonLogger.logCall();
                
		this.velocity.add(velocity);
			
		SkeletonLogger.logReturn();
                
                
                //Kimenet
                    kimenet = kimenet.concat(" UjSebbessegvektora: (" + float2tizedes.format(this.velocity.getX()).replace(',','.') + ", " + float2tizedes.format(this.velocity.getY()).replace(',','.') + ")");
                    Controller.println(kimenet);
                //Kimenet vege
	}
        
        public void setVelocity(Vector velocity) {
		
                //Kimenet
                //Float formazo inicializalasa
                    NumberFormat  float2tizedes = NumberFormat.getInstance();
                    float2tizedes.setMinimumFractionDigits(2);
                    float2tizedes.setMaximumFractionDigits(2);

                    String kimenet = "";
                    String className = this.getClass().getName();

                    Pattern classNamePattern = Pattern.compile("[^.]+.([^.]+)");

                    Matcher m = classNamePattern.matcher(className);
                        m.find();



                    kimenet = kimenet.concat(m.group(1) + " RegiSebbessegvektora: (" + float2tizedes.format(this.velocity.getX()).replace(',','.') + ", " + float2tizedes.format(this.velocity.getY()).replace(',','.') + ");");
                //Kimenet vege     
            
                SkeletonLogger.logCall();
                
		this.velocity = velocity;
			
		SkeletonLogger.logReturn();
                
                
                //Kimenet
                    kimenet = kimenet.concat(" UjSebbessegvektora: (" + float2tizedes.format(this.velocity.getX()).replace(',','.') + ", " + float2tizedes.format(this.velocity.getY()).replace(',','.') + ")");
                    Controller.println(kimenet);
                //Kimenet vege
	}

	/**
	 * 
	 * @param direction
	 */
	public void move(Direction direction) {
		SkeletonLogger.logCall();
		SkeletonLogger.logReturn();
	}

	public Vector getVelocity() {
		
		
		SkeletonLogger.logCall();
		
		SkeletonLogger.logReturn();
		
		return this.velocity;
	}

	public void setPosition(Vector v) {
	
                boolean inInitializeSection = false;
                
                if(this.position == null)
                    inInitializeSection = true;
            
                //Kimenet
                //Float formazo inicializalasa
                    NumberFormat  float2tizedes = NumberFormat.getInstance();
                    float2tizedes.setMinimumFractionDigits(2);
                    float2tizedes.setMaximumFractionDigits(2);

                    String kimenet = "";
                    String className = this.getClass().getName();

                    Pattern classNamePattern = Pattern.compile("[^.]+.([^.]+)");

                    Matcher m = classNamePattern.matcher(className);
                        m.find();


                    if(!inInitializeSection)
                    kimenet = kimenet.concat(m.group(1) + " RegiPozicioja: (" + float2tizedes.format(this.position.getX()).replace(',','.') + ", " + float2tizedes.format(this.position.getY()).replace(',','.') + ");");
                //Kimenet vege        
                       
            
                SkeletonLogger.logCall();
                
                this.position = v;
	
		SkeletonLogger.logReturn();
                
                
                //Kimenet
                    if(!inInitializeSection)
                    kimenet = kimenet.concat(" UjPozicioja: (" + float2tizedes.format(this.position.getX()).replace(',','.') + ", " + float2tizedes.format(this.position.getY()).replace(',','.') + ")");
                    if(!inInitializeSection)
                    Controller.println(kimenet);
                //Kimenet vege
                
	}
        
        /*
         * 
         * 
         */
        public void setPolygon(CustomPolygon p) {
		SkeletonLogger.logCall();
                polygon = p;
		SkeletonLogger.logReturn();
	}

	public LevelPartManager getLevelPartManager() {
		
		
		SkeletonLogger.logCall();
		
		SkeletonLogger.logReturn();
		
		return this.levelPartManager;
	}

	/**
	 * 
	 * @param levelPartManager
	 */
	public void setLevelPartManager(LevelPartManager levelPartManager) {
		SkeletonLogger.logCall();
		
		SkeletonLogger.logReturn();
		
		this.levelPartManager = levelPartManager;
	}

}